package com.lkd.handler;

import com.lkd.business.MsgHandler;
import com.lkd.business.Topic;
import com.lkd.config.TopicConfig;
import com.lkd.contract.VendoutResultContract;
import com.lkd.service.ChannelService;
import com.lkd.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@Topic(TopicConfig.VMS_RESULT_TOPIC)
public class VendoutResultMsgHandler implements MsgHandler {

    @Autowired
    private ChannelService channelService;

    @Override
    public void process(String jsonMsg) {
        log.info("接收到出货结果，jsonMsg={}",jsonMsg);
        if(StringUtils.isBlank(jsonMsg)){
            return ;
        }
        try{
            VendoutResultContract vendoutResultContract = JsonUtil.getByJson(jsonMsg, VendoutResultContract.class);
//            处理出货结果通知
            channelService.vendoutResult(vendoutResultContract);
        }catch(Exception e){
            log.error("售货机处理出货结果失败");
            e.printStackTrace();
        }
    }
}
